package redis

import (
	"errors"
	"fmt"
	"github.com/go-redis/redis"
)

func RedisClient(hand func(rdb *redis.Client) error) error {
	rdb := redis.NewClient(&redis.Options{
		Addr:     "service-redis:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	defer rdb.Close()

	_, err := rdb.Ping().Result()
	if err != nil {
		return errors.New("redis is not client error: " + err.Error())
	}
	fmt.Println("redis connection successful")

	return hand(rdb)
}
